package sse.controller;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/plain")
public class PlainController {
    private static final Logger logger = LogManager.getLogger(PlainController.class);

    @PostMapping(value = "/query", produces = MediaType.APPLICATION_JSON_VALUE)
    public Map<String, String> streamSse(HttpServletRequest request) {
        Enumeration<String> headerNames = request.getHeaderNames();
        logger.info("request header names: {}", headerNames);
//        while (headerNames.hasMoreElements()) {
//            String headerName = request.getHeaderNames().nextElement();
//            String headerValue = request.getHeader(headerName);
//            logger.info("request header:{}={}", headerName, headerValue);
//        }
        Map<String, String> map = new HashMap<>();
        map.put("time", LocalDateTime.now().toString());
        return map;
    }
}
